package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import pojo.Customer;
import dao.CustomerDao;

@Repository(value="customerDao")
public class CustomerDaoImpl implements CustomerDao {
	@PersistenceContext(name="pUnitName")
	private EntityManager em;
	
	public Customer addCustomer(Customer c) {
		em.persist(c);
		return c;
	}

	@Override
	public Customer findCustomerByName(String cname) 
	{
		String jpql="select c from Customer c where c.cname=:cname ";
		List<Customer> ls=em.createQuery(jpql)
				.setParameter("cname", cname)
				.getResultList();
		if(ls.isEmpty()) return null;
		else return ls.get(0);
	}
		
}





